/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use crate::common::ErrorCode;
use crate::log_e;
use crate::singleton_registry;
use crate::traits::edit_session::EditSession;
use crate::Challenge;

pub trait EditSessionManager {
    fn open_edit_session<'a>(&'a mut self, user_id: i32) -> Result<&'a mut EditSession, ErrorCode>;
    fn close_edit_session(&mut self) -> ();
    fn get_edit_session<'a>(&'a mut self) -> Result<&'a mut EditSession, ErrorCode>;
    fn check_session_valid(&mut self, _user_id: i32) -> Result<(), ErrorCode>;
    fn get_session_challenge(&mut self,  _user_id: i32) -> Result<Challenge , ErrorCode>;
    fn check_challenge(&mut self, user_id: i32, challenge: Challenge) -> Result<(), ErrorCode>;
}

pub struct DummyEditSessionManager;

impl EditSessionManager for DummyEditSessionManager {
    fn open_edit_session<'a>(&'a mut self, _user_id: i32) -> Result<&'a mut EditSession, ErrorCode> {
        log_e!("not implemented");
        Err(ErrorCode::GeneralError)
    }

    fn close_edit_session(&mut self) -> () {
        log_e!("not implemented");
    }

    fn get_edit_session<'a>(&'a mut self) -> Result<&'a mut EditSession, ErrorCode> {
        log_e!("not implemented");
        Err(ErrorCode::GeneralError)
    }

    fn check_session_valid(&mut self, _user_id: i32) -> Result<(), ErrorCode> {
        log_e!("not implemented");
        Err(ErrorCode::GeneralError)
    }

    fn get_session_challenge(&mut self,  _user_id: i32) -> Result<Challenge , ErrorCode> {
        log_e!("not implemented");
        Err(ErrorCode::GeneralError)
    }

    fn check_challenge(&mut self, _user_id: i32, _challenge: Challenge) -> Result<(), ErrorCode> {
        log_e!("not implemented");
        Err(ErrorCode::GeneralError)
    }
}

singleton_registry!(
    EditSessionManagerRegistry,
    EditSessionManager,
    DummyEditSessionManager
);
